
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
  <div>
    <h1>添加分类</h1>
    <p>分类名称：<input type="text" v-model="form.name"></p>
    <p>分类选择：<select v-model="form.father">
      <option v-for="i in cate" :value="i.id">{{ i.name }}</option>

    </select></p>
    <button @click="add_cate">提交</button>

    <h1>添加商品</h1>
    <p>商品名称：<input type="text" v-model="shop.name"></p>
    <p>商品价格：<input type="text" v-model="shop.price"></p>
    <p>商品库存：<input type="text" v-model="shop.stock"></p>
    <p>商品内容：<input type="text" v-model="shop.content"></p>
    <p>商品分类：<select v-model="shop.cate">
      <option :value="j.id" v-for="j in cate">{{ j.name }}</option>

    </select></p>
    <button @click="add_shop">添加</button>

    <table border="1" cellspacing="0">
      <tr>
        <td>商品名称</td>
        <td>
          <button @click="order('price')">商品价格</button>
        </td>
        <td>
          <button @click="order('stock')">商品库存</button>
        </td>
        <td>商品内容</td>
        <td>商品分类</td>
      </tr>
      <tr v-for="i in shoplist">
        <td>{{ i.name }}</td>
        <td>{{ i.price }}</td>
        <td>{{ i.stock }}</td>
        <td>{{ i.content }}</td>
        <td>{{ i.cate.name }}</td>
      </tr>

    </table>

  </div>
</template>

<script>
export default {
  name: "add_cate",
  data() {
    return {
      form: {},
      cate: [],
      shop: {},
      shoplist: []
    }
  },
  methods: {
    add_cate() {
      this.$axios.post('catem/', this.form)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.get_cate()
            this.form = {}
          } else {
            alert('添加失败')
          }

        })
    },
    get_cate() {
      this.$axios.get('catem/')
        .then(res => {
          if (res.data.code == 200) {
            this.cate = res.data.list
          }
        })
    },
    add_shop() {
      this.$axios.post('shopm/', this.shop)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.shop = {}
          } else {
            alert('添加失败')
          }
        })
    },
    get_shop() {
      this.$axios.get('shopm/')
        .then(res => {
          if (res.data.code == 200) {
            this.shoplist = res.data.list

          }
        })
    },
    order(sorted) {
      this.$axios.get('shopm/?sorted=' + sorted)
        .then(res => {
          if (res.data.code == 200) {
            this.shoplist = res.data.list
          }
        })

    }
  },
  mounted() {
    this.get_cate()
    this.get_shop()
  }

}
</script>

<style scoped>

</style>